﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DLL.Entities;
using DLL.Entities.Config;

namespace RAD
{
    public partial class RAD : Form
    {
        ReadXML xRead = null;
        WriteXML xWrite = null;
        RADConfig configR = null;

        TargetInfo target = new TargetInfo();//instantiates object to be used when ACQUIRE button is pressed

        public RAD()
        {
            InitializeComponent();

            xRead = new ReadXML();
            xWrite = new WriteXML();
            configR = xRead.ReadRADConfig();
        }

        private void RAD_Load(object sender, EventArgs e)
        {
            xWrite.WriteRADStatus(configR.RADStatusDir);
            xWrite.WriteRADEvent(target, configR.RADEventDir);
            tWrite.Enabled = true;
            lblVersion.Text = configR.Version.ToString();
        }

        // Sends Offline status to COM when form is closed
        private void RAD_FormClosed(object sender, FormClosedEventArgs e)
        {
            tWrite.Enabled = false;
            target.Speed = 0;
            xWrite.WriteRADEvent(target, configR.RADEventDir);
        }

        public void tWrite_Tick(object sender, EventArgs e)
        {
            // Send Status
            xWrite.WriteRADStatus(configR.RADStatusDir);
        }

        private void btnAcquire_Click(object sender, EventArgs e)
        {
            btnSend.Enabled = true;

            radMissle.Enabled = false;
            radAircraft.Enabled = false;
            radBird.Enabled = false;
            radOther.Enabled = false;

            target.RandomNum();
            txtAlt.Text = target.Altitude.ToString();
            txtSpeed.Text = target.Speed.ToString();
            txtDist.Text = target.Distance.ToString();
            txtHead.Text = target.Heading.ToString();
            txtPosition.Text = target.Position.ToString();

            if (target.Speed > 1600)
            {
                radMissle.Checked = true;
                radMissle.Enabled = true;
            }

            else if (target.Speed <= 1600 && target.Speed > 90)
            {
                radAircraft.Checked = true;
                radAircraft.Enabled = true;
            }

            else if (target.Speed <= 90 && target.Speed > 5)
            {
                radBird.Checked = true;
                radBird.Enabled = true;
            }

            else if (target.Speed <= 5)
            {
                radOther.Checked = true;
                radOther.Enabled = true;
            }
        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            xWrite.WriteRADEvent(target, configR.RADEventDir);
            btnSend.Enabled = false;
        }

       
    }
}
